home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 September / Chip_2002-09_cd1.bin / sharewar / slunec / app / httrack.exe / {app} / src_win / WinHTTrack / OptionTab7.cpp < prev    next >
C/C++ Source or Header  |  2002-05-22  |  9KB  |  327 lines

  1. // OptionTab7.cpp : implementation file
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "Shell.h"
  6. #include "OptionTab7.h"
  7. #include "AddFilter.h"
  8.  
  9. /* basic HTTrack defs */
  10. extern "C" {
  11.   #include "htsglobal.h"
  12. }
  13.  
  14. #ifdef _DEBUG
  15. #define new DEBUG_NEW
  16. #undef THIS_FILE
  17. static char THIS_FILE[] = __FILE__;
  18. #endif
  19.  
  20. /////////////////////////////////////////////////////////////////////////////
  21. // COptionTab7 property page
  22.  
  23. IMPLEMENT_DYNCREATE(COptionTab7, CPropertyPage)
  24.  
  25. COptionTab7::COptionTab7() : CPropertyPage(COptionTab7::IDD)
  26. {
  27.   // Patcher titre
  28.   if (LANG_T(-1)) {    // Patcher en franτais
  29.     m_psp.pszTitle=LANG(LANG_IOPT7); // titre
  30.     m_psp.dwFlags|=PSP_USETITLE;
  31.   }
  32.   m_psp.dwFlags|=PSP_HASHELP;
  33.   //
  34.     //{{AFX_DATA_INIT(COptionTab7)
  35.     m_url2 = _T("");
  36.     //}}AFX_DATA_INIT
  37. }
  38.  
  39. COptionTab7::~COptionTab7()
  40. {
  41. }
  42.  
  43. void COptionTab7::DoDataExchange(CDataExchange* pDX)
  44. {
  45.     CPropertyPage::DoDataExchange(pDX);
  46.     //{{AFX_DATA_MAP(COptionTab7)
  47.     DDX_Text(pDX, IDC_URL2, m_url2);
  48.     //}}AFX_DATA_MAP
  49. }
  50.  
  51.  
  52. BEGIN_MESSAGE_MAP(COptionTab7, CPropertyPage)
  53.     //{{AFX_MSG_MAP(COptionTab7)
  54.     ON_BN_CLICKED(IDC_ADD1, OnAdd1)
  55.     ON_BN_CLICKED(IDC_ADD2, OnAdd2)
  56.     ON_BN_CLICKED(IDC_CHECK1, OnCheck1)
  57.     ON_BN_CLICKED(IDC_CHECK2, OnCheck2)
  58.     ON_BN_CLICKED(IDC_CHECK3, OnCheck3)
  59.     //}}AFX_MSG_MAP
  60.   ON_NOTIFY_EX( TTN_NEEDTEXT, 0, OnToolTipNotify )
  61. END_MESSAGE_MAP()
  62.  
  63. /////////////////////////////////////////////////////////////////////////////
  64. // COptionTab7 message handlers
  65.  
  66. void NewFilter(int i,char* s) {  // 0: forbid 1: accept
  67.   CAddFilter AddF;
  68.   AddF.type=i;
  69.   if (AddF.type==0)
  70.     AddF.m_addtype=LANG(LANG_B20); /*"Links following this rule will be forbidden:"*/
  71.   else
  72.     AddF.m_addtype=LANG(LANG_B21); // "Links following this rule will be accepted:";
  73.   if (AddF.DoModal()==IDOK) {
  74.     char query[256],t[256],as[256];
  75.     char* q;
  76.     strcpy(s,"");
  77.     strcpy(query,AddF.m_afquery);
  78.     q=query;
  79.     
  80.     if (AddF.m_aftype==10) {
  81.       if (i==0)
  82.         strcpy(s,"-");
  83.       else
  84.         strcpy(s,"+");
  85.       strcat(s,"*");
  86.     } else {
  87.       while(strlen(q)>0) {
  88.         while ((*q==' ') || (*q==',')) q++;
  89.         strcpy(t,"");
  90.         {  // prochain (sΘparΘ par des ,)
  91.           char *a,*b;
  92.           a=strchr(q,' ');
  93.           b=strchr(q,',');
  94.           if (a && b) {  // dΘpartager
  95.             if ((int) b < (int) a)
  96.               a=b;
  97.           } else if (b) a=b;
  98.           
  99.           if (a) {
  100.             strcpy (t,"");
  101.             strncat(t,q,(int) a-(int) q);
  102.             q=a+1;
  103.           } else {
  104.             strcpy(t,q);
  105.             strcpy(q,"");
  106.           }
  107.         }
  108.         
  109.         if (strlen(t)>0) {
  110.           strcpy(as,"");
  111.           switch (AddF.m_aftype) {
  112.           case 0:  // ext
  113.             sprintf(as,"*.%s",t);
  114.             break;
  115.           case 1:  // contient
  116.             sprintf(as,"*/*%s*",t);
  117.             break;
  118.           case 2:  // this one
  119.             sprintf(as,"*/%s",t);
  120.             break;
  121.           case 3:  // folder contains
  122.             sprintf(as,"*/*%s*/*",t);
  123.             break;
  124.           case 4:  // this folder
  125.             sprintf(as,"*/%s/*",t);
  126.             break;
  127.           case 5:  // domaine
  128.             sprintf(as,"*[name].%s/*",t);
  129.             break;
  130.           case 6:  // contien
  131.             sprintf(as,"*[name].*[name]%s*[name].*[name]/*",t);
  132.             break;
  133.           case 7:  // host
  134.             sprintf(as,"%s/*",t);
  135.             break;
  136.           case 8:  // link contient
  137.             sprintf(as,"*%s*",t);
  138.             break;
  139.           case 9:  // lien exact
  140.             sprintf(as,"%s",t);
  141.             break;
  142.           }
  143.           if (strlen(as)>0) {
  144.             if (i==0)
  145.               strcat(s,"-");
  146.             else
  147.               strcat(s,"+");
  148.             strcat(s,as);
  149.             strcat(s,"\x0d\x0a");
  150.           }
  151.         }
  152.       }
  153.       
  154.     }
  155.  
  156.   } else strcpy(s,"");
  157. }
  158.  
  159.  
  160. void COptionTab7::OnAdd1() 
  161. {
  162.   char s[256]; s[0]='\0';
  163.   NewFilter(0,s);
  164.   if (strlen(s)>0) {
  165.     char tempo[HTS_URLMAXSIZE*4];
  166.     {
  167.       CString st;
  168.       GetDlgItemText(IDC_URL2,st);
  169.       strcpy(tempo,st);
  170.     }
  171.     if (strlen(tempo)>0) {
  172.       if ((tempo[strlen(tempo)-1]!=' ') && (tempo[strlen(tempo)-1]!='\n') && (tempo[strlen(tempo)-1]!=13))
  173.         strcat(tempo,"\x0d\x0a");
  174.     }
  175.     strcat(tempo,s);
  176.     //    m_url2=tempo;
  177.     SetDlgItemText(IDC_URL2,tempo);
  178.   }
  179. }
  180.  
  181. void COptionTab7::OnAdd2() 
  182. {
  183.   char s[256]; s[0]='\0';
  184.   NewFilter(1,s);
  185.   if (strlen(s)>0) {
  186.     char tempo[HTS_URLMAXSIZE*2];
  187.     {
  188.       CString st;
  189.       GetDlgItemText(IDC_URL2,st);
  190.       strcpy(tempo,st);
  191.     }
  192.     if (strlen(tempo)>0) {
  193.       if ((tempo[strlen(tempo)-1]!=' ') && (tempo[strlen(tempo)-1]!='\n') && (tempo[strlen(tempo)-1]!=13))
  194.         strcat(tempo,"\x0d\x0a");
  195.     }
  196.     strcat(tempo,s);
  197.     //    m_url2=tempo;
  198.     SetDlgItemText(IDC_URL2,tempo);
  199.   }
  200. }
  201.  
  202. BOOL COptionTab7::OnInitDialog() 
  203. {
  204.     CPropertyPage::OnInitDialog();
  205.   EnableToolTips(true);     // TOOL TIPS
  206.  
  207.   // mode modif α la volΘe
  208.   if (modify==1) {
  209.     GetDlgItem(IDC_ADD1) ->ModifyStyle(0,WS_DISABLED);
  210.     GetDlgItem(IDC_ADD2) ->ModifyStyle(0,WS_DISABLED);
  211.     GetDlgItem(IDC_URL2) ->ModifyStyle(0,WS_DISABLED);
  212.     GetDlgItem(IDC_STATIC_finfo) ->ModifyStyle(0,WS_DISABLED);
  213.     GetDlgItem(IDC_STATIC_tip) ->ModifyStyle(0,WS_DISABLED);
  214.   } else {
  215.     GetDlgItem(IDC_ADD1) ->ModifyStyle(WS_DISABLED,0);
  216.     GetDlgItem(IDC_ADD2) ->ModifyStyle(WS_DISABLED,0);
  217.     GetDlgItem(IDC_URL2) ->ModifyStyle(WS_DISABLED,0);
  218.     GetDlgItem(IDC_STATIC_finfo) ->ModifyStyle(WS_DISABLED,0);
  219.     GetDlgItem(IDC_STATIC_tip) ->ModifyStyle(WS_DISABLED,0);
  220.   }
  221.  
  222.   // Patcher l'interface pour les Franτais ;-)
  223.   if (LANG_T(-1)) {    // Patcher en franτais
  224.     SetWindowText(LANG(LANG_B9)); // "Filtres");
  225.     SetDlgItemText(IDC_STATIC_finfo,LANG(LANG_B10)); // "Vous pouvez exclure ou accepter plusieurs URLs ou liens, en utilisant les jokers\nVous pouvez utiliser les virgules ou les espaces entre les filtres\nExemple: +*.zip,-www.*.com,-www.*.edu/cgi-bin/*.cgi");
  226.     SetDlgItemText(IDC_ADD1,LANG(LANG_B11)); // "Exclure lien(s)..");
  227.     SetDlgItemText(IDC_ADD2,LANG(LANG_B12)); // "Accepter lien(s)..");
  228.     SetDlgItemText(IDC_STATIC_tip,LANG(LANG_B13)); // "Conseil: Si vous voulez accepter tous les fichiers gif d'un site, utilisez quelque chose comme +www.monweb.com/*.gif\n(+*.gif autorisera TOUS les fichiers gif sur TOUS les sites)");
  229.   }
  230.  
  231.     return TRUE;  // return TRUE unless you set the focus to a control
  232.                   // EXCEPTION: OCX Property Pages should return FALSE
  233. }
  234.  
  235.  
  236.  
  237. // ------------------------------------------------------------
  238. // TOOL TIPS
  239. //
  240. // ajouter dans le .cpp:
  241. // remplacer les deux Wid1:: par le nom de la classe::
  242. // dans la message map, ajouter
  243. // ON_NOTIFY_EX( TTN_NEEDTEXT, 0, OnToolTipNotify )
  244. // dans initdialog ajouter
  245. // EnableToolTips(true);     // TOOL TIPS
  246. //
  247. // ajouter dans le .h:
  248. // char* GetTip(int id);
  249. // et en generated message map
  250. // afx_msg BOOL OnToolTipNotify( UINT id, NMHDR * pNMHDR, LRESULT * pResult );
  251. BOOL COptionTab7::OnToolTipNotify( UINT id, NMHDR * pNMHDR, LRESULT * pResult )
  252. {
  253.   TOOLTIPTEXT *pTTT = (TOOLTIPTEXT *)pNMHDR;
  254.   UINT nID =pNMHDR->idFrom;
  255.   if (pTTT->uFlags & TTF_IDISHWND)
  256.   {
  257.     // idFrom is actually the HWND of the tool
  258.     nID = ::GetDlgCtrlID((HWND)nID);
  259.     if(nID)
  260.     {
  261.       char* st=GetTip(nID);
  262.       if (st != "") {
  263.         pTTT->lpszText = st;
  264.         pTTT->hinst = AfxGetResourceHandle();
  265.         return(TRUE);
  266.       }
  267.     }
  268.   }
  269.   return(FALSE);
  270. }
  271. char* COptionTab7::GetTip(int ID)
  272. {
  273.   switch(ID) {
  274.     case IDC_ADD1: return LANG(LANG_C1);   /*"Add refuse filter"*/ break;
  275.     case IDC_ADD2: return LANG(LANG_C2);   /*"Add accept filter"*/ break;
  276.     case IDC_URL2: return LANG(LANG_C3);   /*"Extra filters"*/ break;
  277.   }
  278.   return "";
  279. }
  280. // TOOL TIPS
  281. // ------------------------------------------------------------
  282.  
  283. void COptionTab7::EnsureIncluded(BOOL state, CString filter)  {
  284.   /* wipe all selected filters */
  285.   CString st;
  286.   CString ftok=filter;
  287.   GetDlgItemText(IDC_URL2,st);
  288.   ftok+=" ";
  289.   while(ftok.Find(' ')>=0) {
  290.     CString token=ftok.Mid(0,ftok.Find(' '));
  291.     ftok=ftok.Mid(ftok.Find(' ')+1);
  292.     ftok.TrimLeft();
  293.     st.Replace(token,"");
  294.     st.Replace("\r"," ");
  295.     st.Replace("\t"," ");
  296.     st.Replace("  "," ");
  297.     st.Replace(" \n","\n");
  298.     st.Replace("\n ","\n");
  299.     st.Replace("\n\n","\n");
  300.   }
  301.   st.TrimLeft();
  302.   st.TrimRight();
  303.   /* add ? */
  304.   if (state) {
  305.     st+="\n";
  306.     st+=filter;
  307.   }
  308.   st.Replace("\n","\r\n");      // W32 compatible
  309.   SetDlgItemText(IDC_URL2,st);
  310. }
  311.  
  312.  
  313. void COptionTab7::OnCheck1() 
  314. {
  315.   EnsureIncluded(this->IsDlgButtonChecked(IDC_CHECK1),"+*.gif +*.jpg +*.png +*.tif +*.bmp");
  316. }
  317.  
  318. void COptionTab7::OnCheck2() 
  319. {
  320.   EnsureIncluded(this->IsDlgButtonChecked(IDC_CHECK2),"+*.zip +*.tar +*.tgz +*.gz +*.rar +*.z +*.exe");
  321. }
  322.  
  323. void COptionTab7::OnCheck3() 
  324. {
  325.   EnsureIncluded(this->IsDlgButtonChecked(IDC_CHECK3),"+*.mov +*.mpg +*.mpeg +*.avi +*.asf +*.mp3 +*.mp2 +*.rm +*.wav +*.vob +*.qt +*.vid +*.ac3 +*.wma +*.wmv");
  326. }
  327.